home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2002 #9 / K-CD-9-2002.ISO / Freedom Force / data1.cab / System_Files / leveled.py < prev    next >
Encoding:
Python Source  |  2002-03-21  |  4.5 KB  |  142 lines

  1. title = 'LevelEd 0.0a'
  2.  
  3. import Tkinter
  4. import tkFileDialog
  5. import Pmw       
  6. import level
  7. import guimaker
  8. import formgui
  9. import shelve
  10. import os
  11. import os.path
  12.  
  13. from guimixin import *
  14.  
  15.     
  16. # ---------------------------------------------------------------
  17. # Level Editor Window Class
  18. #
  19. class LevelEditor(Pmw.PanedWidget):
  20.     def __init__(self, parent, **kw):
  21.     self.level = None        
  22.         optiondefs = ()
  23.         self.defineoptions(kw, optiondefs)
  24.     Pmw.PanedWidget.__init__(self, parent)
  25.     self.add('left', min=100)
  26.     self.add('right', min=100)
  27.     self.pack(expand=1, fill='both')    
  28.     self.makeWidgets()
  29.     
  30.     def makeWidgets(self):        
  31.         self.widget = formgui.FormGui(self.pane('left'), self.pane('right'))
  32.         
  33.     def editLevel(self, level):
  34.         self.level = level
  35.         self.widget.setMapping(self.level)
  36.  
  37.     def onClose(self):
  38.         if self.level:
  39.             self.widget.onClose()
  40.             self.level = None
  41.                 
  42. # ---------------------------------------------------------------
  43. # Level Editor Application Class
  44. #        
  45. class EditorApp(GuiMixin, guimaker.GuiMaker):
  46.     def start(self):
  47.         self.serverLevelDir = "\\\\Shodan\\Project\\Justice\\Levels"
  48.         self.level = None
  49.         
  50.         self.master.title("LevelEditor")
  51.         self.master.iconname("LevelEd")
  52.       self.master.geometry('800x600+0+0')
  53.         self.menuBar =  [ 
  54.           ('File', 0,                                
  55.               [guimaker.MenuItem('New...',  0, self.doSelectNewFile),   
  56.                guimaker.MenuItem('Open...', 0, self.doOpenLevel),
  57.                guimaker.MenuItem('Quit',    0, self.quit)]   
  58.           ),
  59.     ]
  60.     
  61.     self.toolBar = [
  62.         ('Quit',     self.quit,         {'side': Tkinter.RIGHT}),        
  63.             ('New...',     self.doSelectNewFile,     {'side': Tkinter.LEFT}),      
  64.             ('Open...',     self.doOpenLevel,     {'side': Tkinter.LEFT}),
  65.             ('Publish',    self.doPublishLevel,    {'side': Tkinter.LEFT}),              
  66.         ('Mappings...', self.notdone,         {'side': Tkinter.LEFT}), 
  67.         ('Run',        self.notdone,        {'side': Tkinter.LEFT}), 
  68.         ('Close',    self.doClose,        {'side': Tkinter.LEFT}),
  69.             ]
  70.     
  71.     def makeWidgets(self):
  72.     self.levelEditor = LevelEditor(self, 
  73.         orient='horizontal',
  74.         hull_width = 200,
  75.         hull_height = 200)
  76.         
  77.     def doClose(self):
  78.         self.levelEditor.onClose()
  79.     
  80.     def doImport(self):
  81.         dlg = Pmw.MessageDialog(self, title='Select Layout File',
  82.             defaultbutton = 0,
  83.             message_text = 'Please select the layout level.txt file')
  84.         dlg.iconname('Select Layout File')
  85.      result = dlg.activate()
  86.             
  87.     self.importFileName = tkFileDialog.askopenfilename(
  88.         initialdir="\\\\Shodan\Project\Justice\Art\Data\Level Layout",
  89.         initialfile="level.txt",
  90.             filetypes=[("FF Import Level Layout File", "*.txt")],
  91.         defaultextension = "*.txt",
  92.         title = "Select Level Layout File"
  93.         )
  94.     if self.importFileName:
  95.         print "Importing Layout..."
  96.         self.level.importLayout(self.importFileName)  
  97.         self.levelEditor.editLevel(self.level)
  98.         
  99.     def doSelectNewFile(self):
  100.         self.fileName = tkFileDialog.asksaveasfilename(
  101.         initialdir="C:\IGA\Jsquad\Data\Levels",        
  102.             filetypes=[("FF Level Files", "*.dat")],
  103.         defaultextension = "*.dat",
  104.         title = "Select New Level FileName"
  105.         )
  106.     if self.fileName:
  107.         self.level = level.LevelFile(self.fileName, 1)        
  108.         self.level.initLevel()
  109.         self.doImport()
  110.         self.levelEditor.editLevel(self.level)
  111.  
  112.     def doOpenLevel(self):
  113.     self.fileName = tkFileDialog.askopenfilename(
  114.         initialdir="C:\IGA\Jsquad\Data\Levels",
  115.         filetypes=[("FF Level Files", "*.dat")],
  116.         defaultextension = "*.dat",
  117.         )
  118.     if self.fileName:
  119.         self.level = level.LevelFile(self.fileName, 0)        
  120.         self.levelEditor.editLevel(self.level)
  121.  
  122.     def doPublishLevel(self):
  123.         if self.level:
  124.             cmd = "copy %s %s" % (os.path.normpath(self.fileName), os.path.normpath(self.serverLevelDir))
  125.             print "cmd = %s" % cmd
  126.             os.system(cmd)
  127.             dlg = Pmw.MessageDialog(self, title='Level Published',
  128.                 defaultbutton = 0,
  129.                 message_text = 'The %s file has been published to Shodan' % self.fileName)
  130.             dlg.iconname('Level Published')
  131.             dlg.activate()
  132.         
  133.        
  134. # ---------------------------------------------------------------
  135. # TEST DRIVE
  136. #
  137. if __name__ == '__main__':
  138.     root = Pmw.initialise()
  139.     root.title(title)
  140.     app = EditorApp(root)
  141.     app.mainloop()
  142.